
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
// using MyTools;
using BdPackage;
using System.IO;


public class BaseTestMove : MonoBehaviour
{
    // 在第一次帧更新之前调用 Start
    void Start()
    {
        // BdPackage.BdUtils.log("~~~ BdPackage.BdUtils.log --- haha");
        // BdPackage.BdUtils.log("--- abs_path:", BdPackage.BdTools.get_abs_path_by_obj(gameObject));
        // BdPackage.BdUtils.log("--- BaseTestMove --- BdPackage.BdTools.get_abs_path_by_obj:", BdPackage.BdTools.get_abs_path_by_obj(gameObject));
    }

    // 每帧调用一次 Update
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        Vector2 position = transform.position;
        position.x = position.x + 3.0f * horizontal * Time.deltaTime;
        position.y = position.y + 3.0f * vertical * Time.deltaTime;
        transform.position = position;
    }

    public void btn_change_image()
    {
        string _img_path = BdUtils.join( "images", "lihua_images", "g_front_alert.png");
        string img_path = BdTools.get_static_abs_file_path_on_all_platform(_img_path, overwrite: true);
        // string img_path = BdUtils.join(BdUtils.streaming_data_dir_path, _img_path);
        BdTools.load_img_to_obj_sprite_renderer(gameObject, img_path);
        
    }

    public void btn_load_raw_image()
    {
        string _img_path = BdUtils.join( "images", "lihua_images", "g_front_alert.png");
        string img_path = BdTools.get_static_abs_file_path_on_all_platform(_img_path, overwrite: true);
        
        BdUtils.assert(File.Exists(img_path), $"img_path[p{img_path}]不存在?");

        RawImage imageComponent = gameObject.GetComponent<RawImage>();
        RectTransform rectTransform = imageComponent.rectTransform;
        var img_size = rectTransform.sizeDelta;
        
        Texture2D img = new Texture2D((int)img_size.x, (int)img_size.y);
        
        // Texture2D _img = new Texture2D((int)img_size.x, (int)img_size.y);
        byte[] fileData = File.ReadAllBytes(img_path);
        img.LoadImage(fileData);
        // Graphics.ConvertTexture(_img, img);

        imageComponent.texture = img;

    }
}
